<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2016/6/29
 * Time: 14:48
 */
namespace Mengwu\Controller;

use Mengwu\Api\MwApi;
use Shop\Api\CategoryApi;
use Shop\Api\CategoryPropApi;

class ShoppingController extends BaseStoreController{

    public function cate(){
        $cate_id = I('id');
        if(empty($cate_id)){
            $this->display_404();
        }
        $page_no = I('p',1);
        $page_size = 16;
        $order = I('order',10);
        if(!in_array($order,[10,18,11])){
            $order = 10;
        }

        //查询cate 分类名称
        $map = ['id' => $cate_id];
        $result = apiCall(CategoryApi::GET_INFO,[$map]);
        if($result['status']){
            if(is_null($result['info']))$this->display_404();
            $cate_name = $result['info']['name'];
            $this->assign('cate_name',$cate_name);
            $this->assignTitle($cate_name);
        }else{
            $this->errorPage($result['info']);
        }
        //查询cate prop 属性
        $map = ['cate_id'=>$cate_id];
        $result = apiCall(CategoryPropApi::QUERY_PROP_TABLE,[$map]);
        if($result['status']){
            $this->assign('cate_props',$result['info']);
        }else{
            $this->errorPage($result['info']);
        }
        
        $data = [
            'cate_id' => $cate_id,
            'page_no' => $page_no,
            'page_size' => $page_size,
            'order' => $order
        ];

        $result = mwApi(MwApi::BY_Product_query,$data);

        if($result['status']){
            $product_list = $result['info']['list'];
            $PICTURE_REMOTE_URL = C('PICTURE_REMOTE_URL');
            foreach($product_list as &$val){
                $val['img'] = $PICTURE_REMOTE_URL.$val['img'].'&size=240';
            }
            $show = paging($page_no,$page_size,$result['info']['count'],'mengwu/shopping/cate');
            $this->assign('show',$show);
            $this->assign('product_list',$product_list);
        }

        $this->boye_display();
    }

}